package com.test.demo.myapplication;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
    EditText Name;
    EditText Pass;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.i("手机的imei为",getIMEI(this));

        /*Name=findViewById(R.id.TEXT_NAME);
        Pass=findViewById(R.id.TEXT_PASS);
        Button login=findViewById(R.id.BTN_login);
        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                check(Name.getText().toString().trim(),Pass.getText().toString().trim());
            }
        });*/
    }

    public static final  String  getIMEI(Context context) {
        try{
            //实例化TelephonyManager对象
            TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
            //获取IMEI号
            String imei = telephonyManager.getDeviceId();
            //在次做个验证，也不是什么时候都能获取到的啊
            if (imei == null) {
                imei = "";
            }
            return imei;
        }catch (Exception e){
            e.printStackTrace();
            return "";
        }
    }

    private void check(String name, String pass) {
        if("tanran".equals(name)&& "tanran".equals(pass)){
            Toast.makeText(MainActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(MainActivity.this,"登录失败",Toast.LENGTH_LONG).show();
        }



    }


}
